<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: huajie <banhuajie@163.com>
// +----------------------------------------------------------------------

namespace Admin\Controller;
use Admin\Logic\GoodsLogic;
use Think\AjaxPage;
use Admin\Model\GoodsModel ; 
use Think\Upload ; 
/**
 * 属性控制器
 * @author huajie <banhuajie@163.com>
 */
class ExamController extends AdminController {
	public function index(){
		$this->display();
	}
	public function qusetionadd(){
		$this->display();
	}
	public function qusetionlist(){
		$this->display();
	}
	function addquestext(){
		$this->display('qusetion');
	}


	public function course(){
            $GoodsLogic = M("Goods_category");               
	        $cat_list = $GoodsLogic->where("level='2'")->select();
	        $this->assign('cat_list',$cat_list);        
	        $this->display(); 
	}
	function addcourse(){ 

            if(IS_POST)
            {
            	$post = I('post.');
            	$data = array();
            	$data ['adduser'] = $_SESSION['onethink_admin']['user_auth']['username'];
            	$data ['addtime'] = time();
            	$data ['title'] = $post['title'] ; 
            	$data ['is_show'] = $post['is_show'] ; 
            	$data ['gid'] = $post['parent_id_3'] ; 
 
            	if(0 === intval($post['parent_id_4'])){
            		//加的是目录 
            		$data ['is_cover'] = 1 ; //区分是不是目录
            		$data ['keys'] = 0 ;  
            		if(M('CourseInfo')->add($data)){
            			$this->success('添加成功');
            		}
            	}else{
            		$data ['is_cover'] = 0 ; 
            		$data ['keys'] = 0 ; 

            		$id = M('CourseInfo')->add($data);
            		$father = M('CourseInfo')->where(array('id' => intval($post['parent_id_4'])))->find();
            		if($father) {
            			$father['keys'] .= $father['keys'] . '_' . $id  ;
            			M('CourseInfo')->where(array('id' => $father['id']))->save($father);
            			$this->success('添加成功');
            		}
            	}
            	$this->error('添加失败');
            }
		$this->display(); 

	}
	public function addcourseadd(){
		

	}
	public function coursedelete(){
		$id=$_GET['id'];
		$arr=M("Course")->where("id='{$id}'")->delete();
		if($arr){
			$this->redirect("Admin/Exam/course");
		}else{
			$this->error("删除失败！");
		}
	}
	public function coursecheck(){
		$id=$_GET['id'];
		$list=M("Course")->where("id='{$id}'")->find();
		$this->assign("list",$list);
		$this->display();
	}
	public function courseupload(){
		$id=$_POST['id'];
		$data['title']=$_POST['title'];
		$data['content']=$_POST['content'];
		$data['adduser']=$_SESSION['onethink_admin']['user_auth']['username'];
		$arr=M('Course')->where("id='{$id}'")->save($data);
		if($arr){
			$this->redirect("Admin/Exam/course");
		}else {
			$this->error("修改失败！");
		}
	}
	public function examclass(){
		/**
		 * 班级管理 . 获取班级方式:  goods_category表查询分类 . 再从goods表中查询下级商品 .
		 */
		//分类的获取 .//level 2 
		 $GoodsLogic = new GoodsLogic();        
        $brandList = $GoodsLogic->getSortBrands();
        $categoryList = $GoodsLogic->getSortCategory(array('level' => 2 , 'is_test' => 1)); 
        $this->assign('categoryList',$categoryList);
        $this->assign('brandList',$brandList);
		$this->display();
	}
}